#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: dfs_graph.py 
@version:
@time: 2024/01/24 
"""
array = [
    [0, 1, 0, 1, 1],
    [1, 0, 1, 0, 0],
    [0, 1, 0, 0, 0],
    [1, 0, 0, 0, 1],
    [1, 0, 0, 1, 0],
]
point = [1, 2, 3, 4, 5]


class Graph:
    def __init__(self, point, graph):
        self.graph = graph
        self.point = point
        self.sum = 0
        self.visited = [0 for _ in range(len(graph))]

    def dfs(self, n):
        self.visited[n] = 1
        print(self.point[n])
        self.sum += 1
        if self.sum == len(self.visited):
            return
        for i in range(len(self.graph)):
            if self.graph[n][i] and not self.visited[i]:
                self.dfs(i)


Graph(point, array).dfs(0)
